//
//  SettingViewController.m
//  XYMaterial
//
//  Created by 肖扬 on 15/12/29.
//  Copyright © 2015年 肖扬. All rights reserved.
//

#import "SettingViewController.h"
#import "AppDelegate.h"
#import "AboutUsViewController.h"
@interface SettingViewController ()

@end

@implementation SettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.leftBtn addTarget: self action: @selector(goBackAction) forControlEvents: UIControlEventTouchUpInside];
    NSMutableArray *titleArray = [NSMutableArray arrayWithObjects:@"当前版本",@"关注微信",@"关于我们", nil];
    self.title = @"设置";
    [self.view setBackgroundColor:UIColorFromRGB(0xf3f2f2)];
    // Do any additional setup after loading the view.
    UIView *bgView = [self createViewFrame:CGRectMake(0, 74, SWIDTH, 43*3) bgColor:UIColorFromRGB(0xffffff) tag:0];
    [self.view addSubview:bgView];
    
    for (int i= 0; i<[titleArray count]; i++) {
        UILabel *lab = [self createLabelFrame:CGRectMake(10, 43*i, SWIDTH, 43) title:[titleArray objectAtIndex:i] titleColor:[UIColor blackColor] tag:0];
        lab.textColor =BLACKColor;
        lab.font = [UIFont systemFontOfSize:14];
        [bgView addSubview:lab];
        UIButton *button = [self createButtonFrame:CGRectMake(0, 43*i, SWIDTH, 43) title:@"" viewController:self selector:@selector(buttonClick:) tag:10+i];
        [button setBackgroundColor:[UIColor clearColor]];
        if (i != 0) {
            UIImageView *imageV = [self createImageViewFrame:CGRectMake(SWIDTH - 20, (40 - 12)/2, 7, 12) image:nil imageName:@"引导@2x" tag:0];
            [button addSubview:imageV];
        }else{
            UILabel *lab2 = [self createLabelFrame:CGRectMake(SWIDTH - 100, (43 - 20)/2, 90, 20) title:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] titleColor:GRAYColor tag:0];
            lab2.font = [UIFont systemFontOfSize:12];
            lab2.textAlignment = NSTextAlignmentRight;
            [button addSubview:lab2];
        }
        [bgView addSubview:button];
    }
    UIView *lineView1 = [self createViewFrame:CGRectMake(10, 43-0.5, SWIDTH, 0.5) bgColor:[UIColor grayColor] tag:0];
    lineView1.alpha = 0.3;
    [bgView addSubview:lineView1];
    
    UIView *lineView2 = [self createViewFrame:CGRectMake(10, 86-0.5, SWIDTH, 0.5) bgColor:[UIColor grayColor] tag:0];
    lineView2.alpha = 0.3;
    [bgView addSubview:lineView2];
    
    UIButton *button = [self createButtonFrame:CGRectMake(0, bgView.frame.origin.y + bgView.frame.size.height+10, SWIDTH, 43) title:@"退出登录" viewController:self selector:@selector(logOutClick:) tag:0];
    [button setBackgroundColor:UIColorFromRGB(0xffffff)];
    button.titleLabel.font = [UIFont systemFontOfSize:14];
    [button setTitleColor:BLACKColor forState:0];
    [self.view addSubview:button];

}
-(void)buttonClick:(UIButton *)sender{
    if (sender.tag == 10) {
        return;
    }else if (sender.tag == 11){
        NSLog(@"关注微信");
        AboutUsViewController *aboutUs = [[AboutUsViewController alloc]init];
        aboutUs.title = @"关注微信";
        [self.navigationController pushViewController:aboutUs animated:YES];
    }else{
        NSLog(@"关于我们");
        AboutUsViewController *aboutUs = [[AboutUsViewController alloc]init];
        aboutUs.title = @"关于我们";
        [self.navigationController pushViewController:aboutUs animated:YES];
    }
}
-(void)logOutClick:(UIButton *)sender{
    [appStatus shareAppStatus].loginSuccess = @"0";
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:@"" forKey:@"userInfo"];
    [defaults setObject:@"" forKey:@"certificate"];
    [defaults setObject:@"0" forKey:@"isLogin"];
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
